package com.hwh.blog.web;

import com.hwh.blog.po.Type;
import com.hwh.blog.qu.BlogQuery;
import com.hwh.blog.service.BlogServiceImpl;
import com.hwh.blog.service.TypeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class TypeShowController {
    @Autowired
    TypeServiceImpl typeService;
    @Autowired
    BlogServiceImpl blogService;
    @GetMapping("/types/{id}")
    public String typeshow(@PageableDefault(size = 5) Pageable pageable, String query, Model model,@PathVariable Long id){
        List<Type> list = typeService.listType(10000);
        if (id==-1) {
            id = list.get(0).getId();
        }
        BlogQuery blogQuery = new BlogQuery();
        blogQuery.setTypeiId(id);
        model.addAttribute("types",list);
        model.addAttribute("page",blogService.listBlog(pageable,blogQuery));
        model.addAttribute("activeTypeId",id);
        return "types";
    }
}
